import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import(/* webpackChunkName:"login" */ '@/views/login/login.vue')
const Layout = () => import(/* webpackChunkName:"layout_home" */ '@/views/layout')
const Home = () => import(/* webpackChunkName:"layout_home" */ '@/views/home')
// 材料信息
const MaterialScience = () => import(/* webpackChunkName:"essentialInformation" */ '@/views/essentialInformation/materialScience')
const Warehouse = () => import(/* webpackChunkName:"essentialInformation" */ '@/views/essentialInformation/warehouse')
const Supplier = () => import(/* webpackChunkName:"essentialInformation" */ '@/views/essentialInformation/supplier')
const projectManagement = () => import(/* webpackChunkName:"essentialInformation" */ '@/views/projectManagement')
const majorType = () => import(/* webpackChunkName:"essentialInformation/majorType" */ '@/views/majorType')
const collectCompany = () => import(/* webpackChunkName:"essentialInformation/majorType" */ '@/views/collectCompany')
// 采购申请
const Purchase = () => import(/* webpackChunkName:"purchase" */ '@/views/purchase')
// 采购申请
const Apply = () => import(/* webpackChunkName:"order" */ '@/views/apply')
// 材料出库和入库
const WarehousingApplication = () => import(/* webpackChunkName:"materialScience" */ '@/views/materialScience/warehousingApplication')
const MaterialRequisition = () => import(/* webpackChunkName:"materialScience" */ '@/views/materialScience/materialRequisition')
const StockReturn = () => import(/* webpackChunkName:"materialScience" */ '@/views/materialScience/stockReturn')
//const collect = () => import(/* webpackChunkName:"collect" */ '@/views/collect')
//const MaterialRequisition2 = () => import(/* webpackChunkName:"materialScience" */ '@/views/materialScience/materialRequisition2')
// 库存
const InventoryDetails = () => import(/* webpackChunkName:"inventoryManagement" */ '@/views/inventoryManagement/inventoryDetails')
const InventoryChecking = () => import(/* webpackChunkName:"inventoryManagement" */ '@/views/inventoryManagement/inventoryChecking')
// 报表
const Stock = () => import(/* webpackChunkName:"reportForm" */ '@/views/reportForm/stock')
const Delivery = () => import(/* webpackChunkName:"reportForm" */ '@/views/reportForm/delivery')
const DonArrivalQuery = () => import(/* webpackChunkName:"reportForm" */ '@/views/reportForm/nonArrivalQuery')
const actualCollection = () => import(/* webpackChunkName:"reportForm" */ '@/views/reportForm/actualCollection')
const monthlyStatistics = () => import(/* webpackChunkName:"reportForm" */ '@/views/reportForm/monthlyStatistics')

// 系统设置
const RolesManagement = () => import(/* webpackChunkName:"system" */ '@/views/system/rolesManagement')
const UserManagement = () => import(/* webpackChunkName:"system" */ '@/views/system/userManagement')
// 个人中心
const Settings = () => import(/* webpackChunkName:"settings" */ '@/views/settings')
const Agency = () => import(/* webpackChunkName:"settings" */ '@/views/agency')
const myDone = () => import(/* webpackChunkName:"settings" */ '@/views/myDone')
const ImportApproval = () => import(/* webpackChunkName:"settings" */ '@/views/ImportApproval')

// 审批流程
const approvalProcess = () => import(/* webpackChunkName:"settings" */ '@/views/approvalProcess')
const approvalList = () => import(/* webpackChunkName:"settings" */ '@/views/approvalList')
//const role = () => import(/* webpackChunkName:"role" */ '@/views/role')
Vue.use(VueRouter)

const routes = [{
  path: '/',
  redirect: '/login'
},
{
  path: '/login',
  name: 'login',
  component: Login
},
{
  path: '/layout',
  name: 'layout',
  component: Layout,
  redirect: '/home',
  children: [
    { path: '/home', name: 'home', component: Home, meta: { title: '首页' } },

    // 材料基本信息
    { path: '/essentialInformation/materialScience', name: 'materialScience', component: MaterialScience, meta: { title: '材料信息' } },
    { path: '/essentialInformation/warehouse', name: 'warehouse', component: Warehouse, meta: { title: '仓库信息' } },
    { path: '/essentialInformation/supplier', name: 'supplier', component: Supplier, meta: { title: '供应商信息' } },
    { path: '/projectManagement', name: 'projectManagement', component: projectManagement, meta: { title: '项目信息' } },
    { path: '/majorType', name: 'majorType', component: majorType, meta: { title: '专业类别' } },
    { path: '/collectCompany', name: 'collectCompany', component: collectCompany, meta: { title: '领用单位' } },
    // 材料采购订单
    { path: '/purchase', name: 'purchase', component: Purchase, meta: { title: '物资采购申请' } },
    //材料采购申请
    { path: '/apply', name: 'apply', component: Apply, meta: { title: '材料采购申请' } },
    // 材料出库和入库
    { path: '/materialScience/warehousingApplication', name: 'warehousingApplication', component: WarehousingApplication, meta: { title: '入库申请' } },
    { path: '/materialScience/materialRequisition', name: 'materialRequisition', component: MaterialRequisition, meta: { title: '物资领用' } },
    //{ path: 'collect', name: 'collect', component: collect, meta: { title: '网电工程' } },
    { path: '/materialScience/stockReturn', name: 'stockReturn', component: StockReturn, meta: { title: '物料退库' } },
    // 库存管理
    { path: '/inventoryManagement/inventoryDetails', name: 'inventoryDetails', component: InventoryDetails, meta: { title: '库存明细' } },
    { path: '/inventoryManagement/inventoryChecking', name: 'inventoryChecking', component: InventoryChecking, meta: { title: '库存盘点' } },
    // 报表
    { path: '/reportForm/stock', name: 'stock', component: Stock, meta: { title: '库存查询' } },
    { path: '/reportForm/delivery', name: 'delivery', component: Delivery, meta: { title: '出库流水' } },
    { path: '/reportForm/nonArrivalQuery', name: 'nonArrivalQuery', component: DonArrivalQuery, meta: { title: '未到货查询' } },
    { path: '/reportForm/actualCollection', name: 'actualCollection', component: actualCollection, meta: { title: '领用物料统计' } },
    { path: '/reportForm/monthlyStatistics', name: 'monthlyStatistics', component: monthlyStatistics, meta: { title: '月度物资统计' } },
    // 用户、权限管理
    { path: '/system/rolesManagement', name: 'rolesManagement', component: RolesManagement, meta: { title: '权限管理' } },
    { path: '/system/userManagement', name: 'userManagement', component: UserManagement, meta: { title: '用户管理' } },
    { path: '/settings', name: 'settings', component: Settings, meta: { title: '个人设置' } },
    { path: '/agency', name: 'agency', component: Agency, meta: { title: '待办事项' } },
    { path: '/myDone', name: 'myDone', component: myDone, meta: { title: '已办事项' } },
    { path: '/ImportApproval', name: 'ImportApproval', component: ImportApproval, meta: { title: 'OA审批' } },
    { path: '/approvalProcess', name: 'approvalProcess', component: approvalProcess, meta: { title: '审批流程' } },
    { path: '/approvalList', name: 'approvalList', component: approvalList, meta: { title: '审批配置列表' } },
    //{ path: '/role', name: 'role', component: role, meta: { title: '角色组管理' } }
  ]
}
]

const router = new VueRouter({
  // mode: 'history', // 地址来无#
  routes
})
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 从哪个路径来
  // next() 表示放行，参数：将要跳转的路径
  if (to.path === '/login') {
    return next()
  }
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) {
    return next('/login')
  }
  next()
})

export default router
